package com.qclix.inv.textui;

/**
 * Handles the top menu flow. This is where the program starts.
 */
public class TopMenuHandler extends AbstractActionHandler {
    
    public void handle() {
        boolean correctValue;
        do {
            correctValue = true;
            System.out.println("Choose an action or '0' to exit:");
            System.out.println("\t(1) New invoice");
            System.out.println("\t(2) Get last invoice as PDF");
            System.out.println("\t(3) New client");
            System.out.println();
            System.out.print("Enter choice: (1) ");
            String input = readChoice("1");

            if (input.equals("1")) {
                setNextHandler(FlowHandler.HANDLER.newInvoice);
            } else if (input.equals("2")) {
                setNextHandler(FlowHandler.HANDLER.pdfLastInvoice);
            } else if (input.equals("3")) {
                setNextHandler(FlowHandler.HANDLER.newClient);
            } else if (input.equals("0")) {
                setNextHandler(FlowHandler.HANDLER.exit);
            } else {
                correctValue = false;
                System.out.print("Incorrect value! Enter choice: (1) ");
            }
        } while (! correctValue);
    }
}
